package com.xbongbong.saas.help;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.distributor.dto.CreditTemporaryLimitDeleteBatchDTO;
import com.xbongbong.distributor.dto.DistributorCommunicateDeleteBatchDTO;
import com.xbongbong.distributor.dto.DistributorContactDeleteBatchDTO;
import com.xbongbong.distributor.dto.DistributorContractOutStockDeleteBatchDTO;
import com.xbongbong.distributor.dto.DistributorDeleteBatchDTO;
import com.xbongbong.distributor.dto.OrderDeleteBatchDTO;
import com.xbongbong.distributor.vo.CreditTemporaryLimitDeleteBatchVO;
import com.xbongbong.distributor.vo.DistributorCommunicateDeleteBatchVO;
import com.xbongbong.distributor.vo.DistributorContactDeleteBatchVO;
import com.xbongbong.distributor.vo.DistributorContractOutStockDeleteBatchVO;
import com.xbongbong.distributor.vo.DistributorDeleteBatchVO;
import com.xbongbong.distributor.vo.OrderDeleteBatchVO;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.help.CommonHelp;
import com.xbongbong.paas.model.PaasProcessDataModel;
import com.xbongbong.paas.pojo.dto.FormDataDeleteBatchDTO;
import com.xbongbong.paas.pojo.vo.FormDataDeleteBatchVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.paas.toolbox.util.ConstantUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.pro.assemble.pojo.dto.AssembleDeleteBatchDTO;
import com.xbongbong.pro.assemble.pojo.vo.AssembleDeleteBatchVO;
import com.xbongbong.pro.bom.pojo.dto.BomDeleteBatchDTO;
import com.xbongbong.pro.bom.pojo.vo.BomDeleteBatchVO;
import com.xbongbong.pro.communicateplan.pojo.dto.CommunicatePlanDeleteBatchDTO;
import com.xbongbong.pro.competitor.pojo.dto.CompetitorDeleteBatchDTO;
import com.xbongbong.pro.competitor.pojo.dto.CompetitorDeleteBatchVO;
import com.xbongbong.pro.contact.pojo.dto.ContactDeleteBatchDTO;
import com.xbongbong.pro.contact.pojo.vo.ContactDeleteBatchVO;
import com.xbongbong.pro.contract.pojo.dto.ContractDeleteBatchDTO;
import com.xbongbong.pro.contract.pojo.vo.ContractDeleteBatchVO;
import com.xbongbong.pro.costadjust.dto.CostAdjustDeleteBatchDTO;
import com.xbongbong.pro.costadjust.vo.CostAdjustDeleteBatchVO;
import com.xbongbong.pro.customer.pojo.dto.ClueDeleteBatchDTO;
import com.xbongbong.pro.customer.pojo.dto.CustomerDeleteBatchDTO;
import com.xbongbong.pro.customer.pojo.vo.CustomerDeleteBatchVO;
import com.xbongbong.pro.customercommunicate.pojo.dto.CustomerCommunicateDeleteBatchDTO;
import com.xbongbong.pro.customercommunicate.pojo.vo.CustomerCommunicateDeleteBatchVO;
import com.xbongbong.pro.customerstatement.pojo.dto.batch.StatementBatchDeleteDTO;
import com.xbongbong.pro.enums.errorcodes.OutstockErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.instock.pojo.dto.InstockDeleteBatchDTO;
import com.xbongbong.pro.instock.pojo.vo.InstockDeleteBatchVO;
import com.xbongbong.pro.inventory.pojo.dto.InventoryDeleteBatchDTO;
import com.xbongbong.pro.inventory.pojo.vo.InventoryDeleteBatchVO;
import com.xbongbong.pro.invoice.pojo.dto.InvoiceDeleteBatchDTO;
import com.xbongbong.pro.invoice.pojo.vo.InvoiceDeleteBatchVO;
import com.xbongbong.pro.marketManage.pojo.dto.MarketActivityDeleteBatchDTO;
import com.xbongbong.pro.marketManage.pojo.vo.MarketActivityDeleteBatchVO;
import com.xbongbong.pro.opportunity.pojo.dto.OpportunityDeleteBatchDTO;
import com.xbongbong.pro.opportunity.pojo.vo.ClueDeleteBatchVO;
import com.xbongbong.pro.opportunity.pojo.vo.OpportunityDeleteBatchVO;
import com.xbongbong.pro.outstock.pojo.dto.OutstockDeleteBatchDTO;
import com.xbongbong.pro.outstock.pojo.vo.OutstockDeleteBatchVO;
import com.xbongbong.pro.payment.pojo.dto.PaymentDeleteBatchDTO;
import com.xbongbong.pro.payment.pojo.vo.PaymentDeleteBatchVO;
import com.xbongbong.pro.paymentsheet.pojo.dto.PaymentSheetDeleteBatchDTO;
import com.xbongbong.pro.paymentsheet.pojo.vo.PaymentSheetDeleteBatchVO;
import com.xbongbong.pro.paymenttask.pojo.dto.PaymentTaskDeleteBatchDTO;
import com.xbongbong.pro.paymenttask.pojo.vo.PaymentTaskDeleteBatchVO;
import com.xbongbong.pro.payplan.pojo.dto.PayPlanDeleteBatchDTO;
import com.xbongbong.pro.payplan.pojo.vo.PayPlanDeleteBatchVO;
import com.xbongbong.pro.payplansheet.pojo.dto.PayPlanSheetDeleteBatchDTO;
import com.xbongbong.pro.payplansheet.pojo.vo.PayPlanSheetDeleteBatchVO;
import com.xbongbong.pro.product.pojo.dto.ProductDeleteBatchDTO;
import com.xbongbong.pro.product.pojo.vo.ProductDeleteBatchVO;
import com.xbongbong.pro.productionorder.pojo.dto.ProductionOrderDeleteBatchDTO;
import com.xbongbong.pro.productionorder.pojo.vo.ProductionOrderDeleteBatchVO;
import com.xbongbong.pro.purchase.pojo.dto.PurchaseDeleteBatchDTO;
import com.xbongbong.pro.purchase.pojo.vo.PurchaseDeleteBatchVO;
import com.xbongbong.pro.refund.pojo.dto.RefundDeleteBatchDTO;
import com.xbongbong.pro.refund.pojo.vo.RefundDeleteBatchVO;
import com.xbongbong.pro.returned.pojo.dto.ReturnDeleteBatchDTO;
import com.xbongbong.pro.returned.pojo.vo.ReturnDeleteBatchVO;
import com.xbongbong.pro.returnedpurchase.pojo.dto.ReturnedPurchaseDeleteBatchDTO;
import com.xbongbong.pro.returnedpurchase.pojo.vo.ReturnedPurchaseDeleteBatchVO;
import com.xbongbong.pro.supplier.pojo.dto.SupplierDeleteBatchDTO;
import com.xbongbong.pro.supplier.pojo.vo.SupplierDeleteBatchVO;
import com.xbongbong.pro.suppliercommunicate.pojo.dto.SupplierCommunicateDeleteBatchDTO;
import com.xbongbong.pro.suppliercommunicate.pojo.vo.SupplierCommunicateDeleteBatchVO;
import com.xbongbong.pro.suppliercontact.pojo.dto.SupplierContactDeleteBatchDTO;
import com.xbongbong.pro.suppliercontact.pojo.vo.SupplierContactDeleteBatchVO;
import com.xbongbong.pro.transfer.pojo.dto.TransferDeleteBatchDTO;
import com.xbongbong.pro.transfer.pojo.vo.TransferDeleteBatchVO;
import com.xbongbong.pro.warehouse.pojo.dto.WarehouseDeleteBatchDTO;
import com.xbongbong.pro.warehouse.pojo.vo.QuotationDeleteBatchVO;
import com.xbongbong.pro.warehouse.pojo.vo.WarehouseDeleteBatchVO;
import com.xbongbong.pro.workorder.pojo.dto.QuotationDeleteBatchDTO;
import com.xbongbong.pro.workorder.pojo.dto.WarehouseOriDeleteBatchDTO;
import com.xbongbong.pro.workorder.pojo.dto.WorkOrderDeleteBatchDTO;
import com.xbongbong.pro.workorder.pojo.vo.WorkOrderDeleteBatchVO;
import com.xbongbong.pro.workreport.pojo.dto.WorkReportDeleteBatchDTO;
import com.xbongbong.pro.workreport.pojo.vo.WorkReportDeleteBatchVO;
import com.xbongbong.saas.domain.entity.BatchSeqOperationEntity;
import com.xbongbong.saas.domain.entity.CostAdjustProductEntity;
import com.xbongbong.saas.domain.entity.InstockProductEntity;
import com.xbongbong.saas.domain.entity.OutstockProductEntity;
import com.xbongbong.saas.domain.entity.ext.ProductEntityExt;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ProductEnum;
import com.xbongbong.saas.enums.dictionary.BatchSeqOperationEnum;
import com.xbongbong.saas.model.BatchSeqOperationModel;
import com.xbongbong.saas.model.OutstockModel;
import com.xbongbong.saas.model.ProductModel;
import com.xbongbong.saas.service.*;
import com.xbongbong.saas.model.RefundModel;
import com.xbongbong.saas.service.AssembleService;
import com.xbongbong.saas.service.BomBillService;
import com.xbongbong.saas.service.ClueService;
import com.xbongbong.saas.service.CommunicatePlanService;
import com.xbongbong.saas.service.ContactService;
import com.xbongbong.saas.service.ContractService;
import com.xbongbong.saas.service.CostAdjustService;
import com.xbongbong.saas.service.CreditTemporaryLimitService;
import com.xbongbong.saas.service.CustomerCommunicateService;
import com.xbongbong.saas.service.CustomerService;
import com.xbongbong.saas.service.CustomerStatementStatisticService;
import com.xbongbong.saas.service.DistributorCommunicateService;
import com.xbongbong.saas.service.DistributorContactService;
import com.xbongbong.saas.service.DistributorManageService;
import com.xbongbong.saas.service.FundTransferService;
import com.xbongbong.saas.service.InstockService;
import com.xbongbong.saas.service.InventoryService;
import com.xbongbong.saas.service.InvoiceService;
import com.xbongbong.saas.service.MarketActivityService;
import com.xbongbong.saas.service.OpportunityService;
import com.xbongbong.saas.service.OrderOutstockService;
import com.xbongbong.saas.service.OrderService;
import com.xbongbong.saas.service.OriStockService;
import com.xbongbong.saas.service.OtherExpenseService;
import com.xbongbong.saas.service.OtherIncomeService;
import com.xbongbong.saas.service.OutstockService;
import com.xbongbong.saas.service.PayBalanceService;
import com.xbongbong.saas.service.PayPlanService;
import com.xbongbong.saas.service.PayPlanSheetService;
import com.xbongbong.saas.service.PaymentBalanceService;
import com.xbongbong.saas.service.PaymentService;
import com.xbongbong.saas.service.PaymentSheetService;
import com.xbongbong.saas.service.PaymentTaskService;
import com.xbongbong.saas.service.ProductService;
import com.xbongbong.saas.service.ProductionOrderService;
import com.xbongbong.saas.service.PurchaseInvoiceService;
import com.xbongbong.saas.service.PurchaseService;
import com.xbongbong.saas.service.QuotationService;
import com.xbongbong.saas.service.RefundService;
import com.xbongbong.saas.service.ReturnService;
import com.xbongbong.saas.service.ReturnedPurchaseService;
import com.xbongbong.saas.service.SupplierCommunicateService;
import com.xbongbong.saas.service.SupplierContactService;
import com.xbongbong.saas.service.SupplierService;
import com.xbongbong.saas.service.TransferService;
import com.xbongbong.saas.service.WarehouseService;
import com.xbongbong.saas.service.WorkOrderService;
import com.xbongbong.saas.service.WorkReportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * saas删除逻辑
 * @author 吴峰
 * @version 1.0
 * @date 2019-02-26 15:07
 * @since 1.0
 **/
@Component
public class SaasDeleteHelp {

    private static final Logger LOG = LoggerFactory.getLogger(SaasDeleteHelp.class);

    @Resource
    private ProductService productService;
    @Resource
    private TransferService transferService;
    @Resource
    private InventoryService inventoryService;
    @Resource
    private InstockService instockService;
    @Resource
    private AssembleService assembleService;
    @Resource
    private PayPlanService payPlanService;
    @Resource
    private PaymentService paymentService;
    @Resource
    private ProductionOrderService productionOrderService;
    @Resource
    private BomBillService bomBillService;
    @Resource
    private SupplierService supplierService;
    @Resource
    private SupplierContactService supplierContactService;
    @Resource
    private PurchaseService purchaseService;
    @Resource
    private ReturnedPurchaseService returnedPurchaseService;
    @Resource
    private ContactService contactService;
    @Resource
    private CustomerService customerService;
    @Resource
    private OpportunityService opportunityService;
    @Resource
    private ContractService contractService;
    @Resource
    private RefundService refundService;
    @Resource
    private InvoiceService invoiceService;
    @Resource
    private OutstockService outstockService;
    @Resource
    private WorkReportService workReportService;
    @Resource
    @Lazy
    private CustomerCommunicateService customerCommunicateService;
    @Resource
    private PaymentSheetService paymentSheetService;
    @Resource
    private PayPlanSheetService payPlanSheetService;
    @Resource
    private SupplierCommunicateService supplierCommunicateService;
    @Resource
    private CommunicatePlanService communicatePlanService;
    @Resource
    private WarehouseService warehouseService;
    @Resource
    private WorkOrderService workOrderService;
    @Resource
    private QuotationService quotationService;
    @Resource
    private PurchaseInvoiceService purchaseInvoiceService;
    @Resource
    private PayBalanceService payBalanceService;
    @Resource
    private PaymentBalanceService paymentBalanceService;
    @Resource
    private PaymentTaskService paymentTaskService;
    @Resource
    private OriStockService oriStockService;
    @Resource
    private BatchSeqOperationModel batchSeqOperationModel;
    @Resource
    private ProductModel productModel;
    @Resource
    private MarketActivityService marketActivityService;
    @Resource
    private ClueService clueService;
    @Resource
    private DistributorManageService distributorManageService;
    @Resource
    private DistributorCommunicateService distributorCommunicateService;
    @Resource
    private DistributorContactService distributorContactService;
    @Resource
    private CustomerStatementStatisticService customerStatementStatisticService;
    @Resource
    private OrderOutstockService orderOutstockService;
    @Resource
    private ReturnService returnService;
    @Resource
    private OrderService orderService;
    @Resource
    private CreditTemporaryLimitService creditTemporaryLimitService;
    @Resource
    private CostAdjustService costAdjustService;
    @Resource
    private OtherExpenseService otherExpenseService;
    @Resource
    private OtherIncomeService otherIncomeService;
    @Resource
    private FundTransferService fundTransferService;
    @Resource
    private CompetitorService competitorService;
    @Resource
    private CommonHelp commonHelp;
    @Resource
    private OutstockModel outstockModel;
    @Resource
    private PaasProcessDataModel paasProcessDataModel;
    @Resource
    private RefundModel refundModel;


    @Transactional(rollbackFor = Exception.class)
//    @ConcurrentLock(businessType = HandleProductWayEnum.DELETE)
    public FormDataDeleteBatchVO deleteBatch(FormDataDeleteBatchDTO formDataDeleteBatchDTO) throws XbbException {
        FormDataDeleteBatchVO formDataDeleteBatchVO = new FormDataDeleteBatchVO();
        try {
            Integer businessType = formDataDeleteBatchDTO.getBusinessType();
            XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
            switch (xbbRefTypeEnum) {
                case PRODUCT:
                    ProductDeleteBatchDTO productDeleteBatchDTO = new ProductDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, productDeleteBatchDTO);
                    ProductDeleteBatchVO productDeleteBatchVO = productService.deleteBatch(productDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(productDeleteBatchVO.getDeleteIds());
                    break;
                case COMPETITOR:
                    CompetitorDeleteBatchDTO competitorDeleteBatchDTO = new CompetitorDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO,competitorDeleteBatchDTO);
                    CompetitorDeleteBatchVO competitorDeleteBatchVO = competitorService.deleteBatch(competitorDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(competitorDeleteBatchVO.getDeleteIds());
                    break;
                case TRANSFER:
                    TransferDeleteBatchDTO transferDeleteBatchDTO = new TransferDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, transferDeleteBatchDTO);
                    TransferDeleteBatchVO transferDeleteBatchVO = transferService.deleteBatch(transferDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(transferDeleteBatchVO.getDeleteIds());
                    break;
                case INVENTORY:
                    InventoryDeleteBatchDTO inventoryDeleteBatchDTO = new InventoryDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, inventoryDeleteBatchDTO);
                    InventoryDeleteBatchVO inventoryDeleteBatchVO = inventoryService.deleteBatch(inventoryDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(inventoryDeleteBatchVO.getDeleteIds());
                    break;
                case OUTSTOCK:
                case CONTRACT_OUTSTOCK:
                case RETURNED_PURCHASE_OUTSTOCK:
                case OTHER_OUTSTOCK:
                case PRODUCTION_MATERIEL_OUTSTOCK:
                case WORK_ORDER_OUTSTOCK:
                    OutstockDeleteBatchDTO outstockDeleteBatchDTO = new OutstockDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, outstockDeleteBatchDTO);
                    OutstockDeleteBatchVO outstockDeleteBatchVO = outstockService.deleteBatch(outstockDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(outstockDeleteBatchVO.getDeleteIds());
                    break;
                case INSTOCK:
                case PURCHASE_INSTOCK:
                case REFUND_INSTOCK:
                case OTHER_INSTOCK:
                case PRODUCTION_INSTOCK:
                case RETURNED_MATERIEL_INSTOCK:
                    InstockDeleteBatchDTO instockDeleteBatchDTO = new InstockDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, instockDeleteBatchDTO);
                    InstockDeleteBatchVO instockDeleteBatchVO = instockService.deleteBatch(instockDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(instockDeleteBatchVO.getDeleteIds());
                    break;
                case ASSEMBLE:
                    AssembleDeleteBatchDTO assembleDeleteBatchDTO = new AssembleDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, assembleDeleteBatchDTO);
                    AssembleDeleteBatchVO assembleDeleteBatchVO =  assembleService.deleteBatch(assembleDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(assembleDeleteBatchVO.getDeleteIds());
                    break;
                case PAY_PLAN:
                    PayPlanDeleteBatchDTO payPlanDeleteBatchDTO = new PayPlanDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, payPlanDeleteBatchDTO);
                    PayPlanDeleteBatchVO payPlanDeleteBatchVO = payPlanService.deleteBatch(payPlanDeleteBatchDTO);
                    BeanUtil.copyProperties(payPlanDeleteBatchVO, formDataDeleteBatchVO);
                    formDataDeleteBatchVO.setDeleteIds(payPlanDeleteBatchVO.getDeleteIds());
                    break;
                case PAYMENT:
                    PaymentDeleteBatchDTO paymentDeleteBatchDTO = new PaymentDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, paymentDeleteBatchDTO);
                    PaymentDeleteBatchVO paymentDeleteBatchVO = paymentService.deleteBatch(paymentDeleteBatchDTO);
                    BeanUtil.copyProperties(paymentDeleteBatchVO, formDataDeleteBatchVO);
                    formDataDeleteBatchVO.setDeleteIds(paymentDeleteBatchVO.getDeleteIds());
                    break;
                case PRODUCTION_ORDER:
                    ProductionOrderDeleteBatchDTO productionOrderDeleteBatchDTO = new ProductionOrderDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, productionOrderDeleteBatchDTO);
                    ProductionOrderDeleteBatchVO productionOrderDeleteBatchVO = productionOrderService.deleteBatch(productionOrderDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(productionOrderDeleteBatchVO.getDeleteIds());
                    break;
                case SUPPLIER:
                    SupplierDeleteBatchDTO supplierDeleteBatchDTO = new SupplierDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, supplierDeleteBatchDTO);
                    SupplierDeleteBatchVO supplierDeleteBatchVO = supplierService.deleteBatch(supplierDeleteBatchDTO);
                    BeanUtil.copyProperties(supplierDeleteBatchVO, formDataDeleteBatchVO);
                    formDataDeleteBatchVO.setDeleteIds(supplierDeleteBatchVO.getDeleteIds());
                    break;
                case SUPPLIER_CONTACT:
                    SupplierContactDeleteBatchDTO supplierContactDeleteBatchDTO = new SupplierContactDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, supplierContactDeleteBatchDTO);
                    supplierContactDeleteBatchDTO.setSupplierContactIdIn(formDataDeleteBatchDTO.getDataIdList());
                    SupplierContactDeleteBatchVO supplierContactDeleteBatchVO = supplierContactService.deleteBatch(supplierContactDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(supplierContactDeleteBatchVO.getDeleteIds());
                    break;
                case BOM_BILL:
                    BomDeleteBatchDTO bomDeleteBatchDTO = new BomDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, bomDeleteBatchDTO);
                    BomDeleteBatchVO bomDeleteBatchVO = bomBillService.deleteBatch(bomDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(bomDeleteBatchVO.getDeleteIds());
                    break;
                case PURCHASE:
                    PurchaseDeleteBatchDTO purchaseDeleteBatchDTO = new PurchaseDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, purchaseDeleteBatchDTO);
                    PurchaseDeleteBatchVO purchaseDeleteBatchVO = purchaseService.deleteBatch(purchaseDeleteBatchDTO);
                    BeanUtil.copyProperties(purchaseDeleteBatchVO, formDataDeleteBatchVO);
                    formDataDeleteBatchVO.setDeleteIds(purchaseDeleteBatchVO.getDeleteIds());
                    break;
                case RETURNED_PURCHASE:
                    ReturnedPurchaseDeleteBatchDTO returnedPurchaseDeleteBatchDTO = new ReturnedPurchaseDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, returnedPurchaseDeleteBatchDTO);
                    ReturnedPurchaseDeleteBatchVO returnedPurchaseDeleteBatchVO = returnedPurchaseService.deleteBatch(returnedPurchaseDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(returnedPurchaseDeleteBatchVO.getDeleteIds());
                    break;
                case CONTACT:
                    ContactDeleteBatchDTO contactDeleteBatchDTO = new ContactDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, contactDeleteBatchDTO);
                    ContactDeleteBatchVO contactDeleteBatchVO = contactService.deleteBatch(contactDeleteBatchDTO);
                    BeanUtil.copyProperties(contactDeleteBatchVO, formDataDeleteBatchVO);
                    formDataDeleteBatchVO.setDeleteIds(contactDeleteBatchVO.getDeleteIds());
                    break;
                case DISTRIBUTOR_CONTACT:
                    DistributorContactDeleteBatchDTO distributorContactDeleteBatchDTO = new DistributorContactDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, distributorContactDeleteBatchDTO);
                    DistributorContactDeleteBatchVO distributorContactDeleteBatchVO = distributorContactService.deleteBatch(distributorContactDeleteBatchDTO);
                    BeanUtil.copyProperties(distributorContactDeleteBatchVO, formDataDeleteBatchVO);
                    formDataDeleteBatchVO.setDeleteIds(distributorContactDeleteBatchVO.getDeleteIds());
                    break;
                case CUSTOMER_MANAGEMENT:
                    CustomerDeleteBatchDTO customerDeleteBatchDTO = new CustomerDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, customerDeleteBatchDTO);
                    CustomerDeleteBatchVO customerDeleteBatchVO = customerService.deleteBatch(customerDeleteBatchDTO);
                    BeanUtil.copyProperties(customerDeleteBatchVO, formDataDeleteBatchVO);
                    break;
                case CLUE:
                    ClueDeleteBatchDTO clueDeleteBatchDTO = new ClueDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, clueDeleteBatchDTO);
                    ClueDeleteBatchVO clueDeleteBatchVO = clueService.deleteBatch(clueDeleteBatchDTO);
                    BeanUtil.copyProperties(clueDeleteBatchVO, formDataDeleteBatchVO);
                    break;
                case SALES_OPPORTUNITY:
                    OpportunityDeleteBatchDTO opportunityDeleteBatchDTO = new OpportunityDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, opportunityDeleteBatchDTO);
                    OpportunityDeleteBatchVO opportunityDeleteBatchVO = opportunityService.deleteBatch(opportunityDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(opportunityDeleteBatchVO.getDeleteIds());
                    break;
                case CONTRACT:
                    ContractDeleteBatchDTO contractDeleteBatchDTO = new ContractDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, contractDeleteBatchDTO);
                    ContractDeleteBatchVO contractDeleteBatchVO = contractService.deleteBatch(contractDeleteBatchDTO);
                    BeanUtil.copyProperties(contractDeleteBatchVO, formDataDeleteBatchVO);
                    break;
                case REFUND:
                    RefundDeleteBatchDTO refundDeleteBatchDTO = new RefundDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, refundDeleteBatchDTO);
                    RefundDeleteBatchVO refundDeleteBatchVO = refundService.deleteBatch(refundDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(refundDeleteBatchVO.getDeleteIds());
                    break;
                case INVOICE:
                    InvoiceDeleteBatchDTO invoiceDeleteBatchDTO = new InvoiceDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, invoiceDeleteBatchDTO);
                    DelEnum delEnum = DelEnum.DELETE;
                    InvoiceDeleteBatchVO invoiceDeleteBatchVO=invoiceService.deleteBatch(invoiceDeleteBatchDTO, delEnum);
                    BeanUtil.copyProperties(invoiceDeleteBatchVO, formDataDeleteBatchVO);
                    break;
                case PURCHASE_INVOICE:
                    InvoiceDeleteBatchDTO purchaseInvoiceDeleteBatchDTO = new InvoiceDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO,purchaseInvoiceDeleteBatchDTO);
                    InvoiceDeleteBatchVO purchaseInvoiceDeteteBatchVO = purchaseInvoiceService.deleteBatch(purchaseInvoiceDeleteBatchDTO);
                    BeanUtil.copyProperties(purchaseInvoiceDeteteBatchVO, formDataDeleteBatchVO);
                    break;
                case WORK_REPORT:
                case WORKREPORT_DAILY:
                case WORKREPORT_WEEKLY:
                case WORKREPORT_MONTHLY:
                    WorkReportDeleteBatchDTO workReportDeleteBatchDTO = new WorkReportDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, workReportDeleteBatchDTO);
                    WorkReportDeleteBatchVO workReportDeleteBatchVO = workReportService.deleteBatch(workReportDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(workReportDeleteBatchVO.getDeleteIds());
                    break;
                case CUSTOMER_COMMUNICATE:
                    CustomerCommunicateDeleteBatchDTO customerCommunicateDeleteBatchDTO = new CustomerCommunicateDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, customerCommunicateDeleteBatchDTO);
                    customerCommunicateDeleteBatchDTO.setIdIn(formDataDeleteBatchDTO.getDataIdList());
                    CustomerCommunicateDeleteBatchVO communicateDeleteBatchVO = customerCommunicateService.deleteBatch(customerCommunicateDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(communicateDeleteBatchVO.getDeleteIds());
                    break;
                case PAYMENT_SHEET:
                case WRITE_OFF_PREPAYMENT:
                case PREPAYMENT:
                case RED_PAYMENT_SHEET:
                case RED_WRITE_OFF_PREPAYMENT:
                case RED_WRITE_OFF_BALANCE:
                case RED_PREPAYMENT:
                case BAD_DEBT:
                    PaymentSheetDeleteBatchDTO paymentSheetDeleteBatchDTO = new PaymentSheetDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, paymentSheetDeleteBatchDTO);
                    paymentSheetDeleteBatchDTO.setIdIn(formDataDeleteBatchDTO.getDataIdList());
                    delEnum = DelEnum.DELETE;
                    PaymentSheetDeleteBatchVO paymentSheetDeleteBatchVO = paymentSheetService.deleteBatch(paymentSheetDeleteBatchDTO, delEnum);
                    BeanUtil.copyProperties(paymentSheetDeleteBatchVO, formDataDeleteBatchVO);
                    formDataDeleteBatchVO.setDeleteIds(paymentSheetDeleteBatchVO.getDeleteIds());
                    break;
                case PREPAYMENT_BALANCE:
                    List<Long> deleteIdList = paymentBalanceService.deletePaymentBalanceBatch(formDataDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(deleteIdList);
                    break;
                case PAY_SHEET:
                case WRITE_OFF_PREPAY:
                case PREPAY:
                case RED_WRITE_OFF_PAY:
                case RED_WRITE_OFF_PREPAY:
                case RED_PREPAY:
                case BAD_PAY:
                    PayPlanSheetDeleteBatchDTO payPlanSheetDeleteBatchDTO = new PayPlanSheetDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, payPlanSheetDeleteBatchDTO);
                    payPlanSheetDeleteBatchDTO.setIdIn(formDataDeleteBatchDTO.getDataIdList());
                    PayPlanSheetDeleteBatchVO payPlanSheetDeleteBatchVO = payPlanSheetService.deleteBatch(payPlanSheetDeleteBatchDTO);
                    BeanUtil.copyProperties(payPlanSheetDeleteBatchVO, formDataDeleteBatchVO);
                    break;
                case PREPAY_BALANCE:
                    List<Long> deletePayBalanceIdList = payBalanceService.deletePayBalanceBatch(formDataDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(deletePayBalanceIdList);
                    break;
                case SUPPLIER_COMMUNICATE:
                    SupplierCommunicateDeleteBatchDTO supplierCommunicateDeleteBatchDTO = new SupplierCommunicateDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, supplierCommunicateDeleteBatchDTO);
                    SupplierCommunicateDeleteBatchVO supplierCommunicateDeleteBatchVO = supplierCommunicateService.deleteBatch(supplierCommunicateDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(supplierCommunicateDeleteBatchVO.getDeleteIds());
                    break;
                case COMMUNICATE_PLAN:
                    CommunicatePlanDeleteBatchDTO communicatePlanDeleteBatchDTO = new CommunicatePlanDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, communicatePlanDeleteBatchDTO);
                    formDataDeleteBatchVO = communicatePlanService.deleteBatch(communicatePlanDeleteBatchDTO);
                    break;
                case WAREHOUSE:
                    WarehouseDeleteBatchDTO warehouseDeleteBatchDTO = new WarehouseDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, warehouseDeleteBatchDTO);
                    WarehouseDeleteBatchVO warehouseDeleteBatchVO = warehouseService.deleteBatch(warehouseDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(warehouseDeleteBatchVO.getDeleteIds());
                    break;
                case WORK_ORDER:
                    WorkOrderDeleteBatchDTO workOrderDeleteBatchDTO = new WorkOrderDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, workOrderDeleteBatchDTO);
                    WorkOrderDeleteBatchVO workOrderDeleteBatchVO = workOrderService.deleteBatch(workOrderDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(workOrderDeleteBatchVO.getDeleteIds());
                    break;
                case QUOTATION:
                    QuotationDeleteBatchDTO quotationDeleteBatchDTO = new QuotationDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, quotationDeleteBatchDTO);
                    QuotationDeleteBatchVO quotationDeleteBatchVO = quotationService.deleteBatch(quotationDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(quotationDeleteBatchVO.getDeleteIds());
                    break;
                case PAYMENT_TASK:
                    PaymentTaskDeleteBatchDTO paymentTaskDeleteBatchDTO = new PaymentTaskDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, paymentTaskDeleteBatchDTO);
                    PaymentTaskDeleteBatchVO paymentTaskDeleteBatchVO = paymentTaskService.deleteBatch(paymentTaskDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(paymentTaskDeleteBatchVO.getDeleteIds());
                    break;
                case ORI_STOCK:
                    WarehouseOriDeleteBatchDTO warehouseOriDeleteBatchDTO = new WarehouseOriDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, warehouseOriDeleteBatchDTO);
                    oriStockService.deleteBatch(warehouseOriDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(warehouseOriDeleteBatchDTO.getDataIdList());
                    break;
                case MARKET_ACTIVITY:
                    MarketActivityDeleteBatchDTO marketActivityDeleteBatchDTO = new MarketActivityDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, marketActivityDeleteBatchDTO);
                    MarketActivityDeleteBatchVO marketActivityDeleteBatchVO = marketActivityService.deleteBatch(marketActivityDeleteBatchDTO);
                    BeanUtil.copyProperties(marketActivityDeleteBatchVO, formDataDeleteBatchVO);
                    break;
                case CUSTOMER_STATEMENT_STATISTIC:
                    StatementBatchDeleteDTO statementBatchDeleteDTO = new StatementBatchDeleteDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, statementBatchDeleteDTO);
                    customerStatementStatisticService.deleteBatch(statementBatchDeleteDTO);
                    formDataDeleteBatchVO.setDeleteIds(statementBatchDeleteDTO.getDataIdList());
                    break;
                case DISTRIBUTOR_MANAGEMENT:
                    DistributorDeleteBatchDTO distributorDeleteBatchDTO = new DistributorDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, distributorDeleteBatchDTO);
                    DistributorDeleteBatchVO distributorDeleteBatchVO = distributorManageService.deleteBatch(distributorDeleteBatchDTO);
                    BeanUtil.copyProperties(distributorDeleteBatchVO, formDataDeleteBatchVO);
                    break;
                case DISTRIBUTOR_COMMUNICATE:
                    DistributorCommunicateDeleteBatchDTO distributorCommunicateDeleteBatchDTO = new DistributorCommunicateDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, distributorCommunicateDeleteBatchDTO);
                    distributorCommunicateDeleteBatchDTO.setIdIn(formDataDeleteBatchDTO.getDataIdList());
                    DistributorCommunicateDeleteBatchVO distributorCommunicateDeleteBatchVO = distributorCommunicateService.deleteBatch(distributorCommunicateDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(distributorCommunicateDeleteBatchVO.getDeleteIds());
                    break;
                case ORDER:
                    OrderDeleteBatchDTO orderDeleteBatchDTO = new OrderDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, orderDeleteBatchDTO);
                    OrderDeleteBatchVO orderDeleteBatchVO = orderService.deleteBatch(orderDeleteBatchDTO);
                    BeanUtil.copyProperties(orderDeleteBatchVO, formDataDeleteBatchVO);
                    break;
                case ORDER_OUTSTOCK:
                    DistributorContractOutStockDeleteBatchDTO distributorContractOutStockDeleteBatchDTO = new DistributorContractOutStockDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, distributorContractOutStockDeleteBatchDTO);
                    distributorContractOutStockDeleteBatchDTO.setDataIdList(formDataDeleteBatchDTO.getDataIdList());
                    DistributorContractOutStockDeleteBatchVO distributorContractOutStockDeleteBatchVO = orderOutstockService.deleteBatch(distributorContractOutStockDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(distributorContractOutStockDeleteBatchVO.getDeleteIds());
                    break;
                case RETURN:
                    ReturnDeleteBatchDTO returnDeleteBatchDTO = new ReturnDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, returnDeleteBatchDTO);
                    ReturnDeleteBatchVO returnDeleteBatchVO = returnService.deleteBatch(returnDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(returnDeleteBatchVO.getDeleteIds());
                    break;
                case CREDIT_TEMPORARY_LIMIT:
                    // 回退额度
                    CreditTemporaryLimitDeleteBatchDTO temporaryLimitDeleteBatchDTO = new CreditTemporaryLimitDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, temporaryLimitDeleteBatchDTO);
                    CreditTemporaryLimitDeleteBatchVO temporaryLimitDeleteBatchVO = creditTemporaryLimitService.deleteBatch(temporaryLimitDeleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(temporaryLimitDeleteBatchVO.getDeleteIds());
                    break;
                case COST_ADJUST:
                    CostAdjustDeleteBatchDTO deleteBatchDTO = new CostAdjustDeleteBatchDTO();
                    BeanUtil.copyProperties(formDataDeleteBatchDTO, deleteBatchDTO);
                    CostAdjustDeleteBatchVO deleteBatchVO = costAdjustService.deleteBatch(deleteBatchDTO);
                    formDataDeleteBatchVO.setDeleteIds(deleteBatchVO.getDeleteIds());
                    break;
                case OTHER_EXPENSE:
                    formDataDeleteBatchVO = otherExpenseService.deleteBatch(formDataDeleteBatchDTO);
                    break;
                case OTHER_INCOME:
                    formDataDeleteBatchVO = otherIncomeService.deleteBatch(formDataDeleteBatchDTO);
                    break;
                case FUND_TRANSFER:
                    formDataDeleteBatchVO = fundTransferService.deleteBatch(formDataDeleteBatchDTO);
                    break;
                default:
                    break;
            }
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOG.error("saasDeleteHelp.deleteBatch批量删除出错：", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return formDataDeleteBatchVO;
    }

    /**
     * 获取不允许删除的提示
     * @param errorTypeList 不允许删除类型列表
     * @param errorDataList 不允许删除数据
     * @return 返回不允许删除的提示
     */
    public static String getErrorDataMemo(List<String> errorTypeList, List<String> errorDataList) {
        return ConstantUtil.getErrorDataMemo(errorTypeList, errorDataList);
    }



    /**
     * 以前的出入库单删除校验
     * @param corpid
     */
    public Set<Long> checkDocumentDelete(String corpid, List<CostAdjustProductEntity> costAdjustProductEntityList, Map<Long, String> stockToSerialNo) throws XbbException {
        HashSet<Long> parentIdList = new HashSet<>();
        if (CollectionsUtil.isNotEmpty(costAdjustProductEntityList)){
            for (CostAdjustProductEntity productEntity : costAdjustProductEntityList) {
                parentIdList.add(productEntity.getParentId());
            }
        }
        Map<String,Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("parentIdIn", parentIdList);
        param.put("corpid", corpid);
        param.put("del", 0);
        param.put("groupByStr", "parent_id");
        List<BatchSeqOperationEntity> maxIdEntitys = batchSeqOperationModel.findMaxIdEntitys(param);

        Map<Long, BatchSeqOperationEntity> batchSeqOperationMap = new HashMap<>();
        Set<Long> disableBatchProducts = new HashSet<>();
        if (!maxIdEntitys.isEmpty()) {
            for (BatchSeqOperationEntity maxIdEntity : maxIdEntitys) {
                //关闭批次和关闭序列号的情况下可以删除单据
                if (Objects.equals(maxIdEntity.getType(), BatchSeqOperationEnum.DISABLEBATCH.getCode()) || Objects.equals(maxIdEntity.getType(), BatchSeqOperationEnum.DISABLESEQ.getCode())) {
                   continue;
                }
                Long parentId = maxIdEntity.getParentId();
                batchSeqOperationMap.put(parentId, maxIdEntity);
            }
            if (!batchSeqOperationMap.isEmpty() && CollectionsUtil.isNotEmpty(costAdjustProductEntityList)) {
                for (CostAdjustProductEntity entity : costAdjustProductEntityList) {
                    if (batchSeqOperationMap.containsKey(entity.getParentId())) {
                        BatchSeqOperationEntity operationEntity = batchSeqOperationMap.get(entity.getParentId());
                        if (operationEntity.getOperateTime() > entity.getAddTime()){
                            String name = stockToSerialNo.getOrDefault(entity.getCostAdjustId(), "");
                            //查到一个直接抛错
                            BatchSeqOperationEnum batchSeqOperationEnum = BatchSeqOperationEnum.getByCode(operationEntity.getType());
                            String productName = entity.getProductName();
                            if (StringUtil.isNotEmpty(entity.getProductSpecification())) {
                                productName = productName + "(" + entity.getProductSpecification() + ")";
                            }
                            throw new XbbException(OutstockErrorCodeEnum.API_ERROR_212039, String.format(OutstockErrorCodeEnum.API_ERROR_212039.getMsg(), name, productName, batchSeqOperationEnum.getName(), batchSeqOperationEnum.getSaasName()));
                        }
                    }
                }
            }
        }
        param.clear();
        param.put("corpid", corpid);
        param.put("del", 0);
        param.put("idIn", parentIdList);
        List<ProductEntityExt> entitys = productModel.findEntitys(param);
        for (ProductEntityExt entity : entitys) {
            JSONObject data = entity.getData();
            Integer enableBatch = data.getInteger(ProductEnum.ENABLE_BATCH_SHELF_LIFE.getAttr());
            if (!Objects.equals(enableBatch, 1)) {
                disableBatchProducts.add(entity.getId());
            }
        }

        return disableBatchProducts;
    }

    /**
     * 以前的出入库单删除校验
     * @param corpid
     */
    public Set<Long> checkDocumentDelete(String corpid, List<OutstockProductEntity> outstockProductEntityList, List<InstockProductEntity> instockProductEntityList,  Map<Long, String> stockToSerialNo) throws XbbException {
        HashSet<Long> parentIdList = new HashSet<>();
        if (Objects.nonNull(outstockProductEntityList)) {
            for (OutstockProductEntity entity : outstockProductEntityList) {
                parentIdList.add(entity.getParentId());
            }
        }
        if (Objects.nonNull(instockProductEntityList)){
            for (InstockProductEntity instockProductEntity : instockProductEntityList) {
                parentIdList.add(instockProductEntity.getParentId());
            }
        }
        Map<String,Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("parentIdIn", parentIdList);
        param.put("corpid", corpid);
        param.put("del", 0);
        param.put("groupByStr", "parent_id");
        List<BatchSeqOperationEntity> maxIdEntitys = batchSeqOperationModel.findMaxIdEntitys(param);

        Map<Long, BatchSeqOperationEntity> batchSeqOperationMap = new HashMap<>();
        Set<Long> disableBatchProducts = new HashSet<>();
        if (!maxIdEntitys.isEmpty()) {
            for (BatchSeqOperationEntity maxIdEntity : maxIdEntitys) {
                //关闭批次和关闭序列号的情况下可以删除单据
                if (Objects.equals(maxIdEntity.getType(), BatchSeqOperationEnum.DISABLEBATCH.getCode()) || Objects.equals(maxIdEntity.getType(), BatchSeqOperationEnum.DISABLESEQ.getCode())
                        || Objects.equals(maxIdEntity.getType(), BatchSeqOperationEnum.DISABLEGUARANTEEPERIOD.getCode())) {
                    continue;
                }
                Long parentId = maxIdEntity.getParentId();
                batchSeqOperationMap.put(parentId, maxIdEntity);
            }
            if (!batchSeqOperationMap.isEmpty()) {
                if (Objects.nonNull(outstockProductEntityList)) {
                    for (OutstockProductEntity entity : outstockProductEntityList) {
                        if (batchSeqOperationMap.containsKey(entity.getParentId())) {
                            BatchSeqOperationEntity operationEntity = batchSeqOperationMap.get(entity.getParentId());
                            if (operationEntity.getOperateTime() > entity.getAddTime()){
                                String name = stockToSerialNo.getOrDefault(entity.getOutWarehouseId(), "");
                                //查到一个直接抛错
                                BatchSeqOperationEnum batchSeqOperationEnum = BatchSeqOperationEnum.getByCode(operationEntity.getType());
                                String productName = entity.getProductName();
                                if (StringUtil.isNotEmpty(entity.getProductSpecification())) {
                                    productName = productName + "(" + entity.getProductSpecification() + ")";
                                }
                                throw new XbbException(OutstockErrorCodeEnum.API_ERROR_212039, String.format(OutstockErrorCodeEnum.API_ERROR_212039.getMsg(), name, productName, batchSeqOperationEnum.getName(), batchSeqOperationEnum.getSaasName()));
                            }
                        }
                    }
                }
                if (Objects.nonNull(instockProductEntityList)){
                    for (InstockProductEntity entity : instockProductEntityList) {
                        if (batchSeqOperationMap.containsKey(entity.getParentId())) {
                            BatchSeqOperationEntity operationEntity = batchSeqOperationMap.get(entity.getParentId());
                            if (operationEntity.getOperateTime() > entity.getAddTime()){
                                String name = stockToSerialNo.getOrDefault(entity.getIntoWarehouseId(), "");
                                //查到一个直接抛错
                                BatchSeqOperationEnum batchSeqOperationEnum = BatchSeqOperationEnum.getByCode(operationEntity.getType());
                                String productName = entity.getProductName();
                                if (StringUtil.isNotEmpty(entity.getProductSpecification())) {
                                    productName = productName + "(" + entity.getProductSpecification() + ")";
                                }
                                throw new XbbException(OutstockErrorCodeEnum.API_ERROR_212039, String.format(OutstockErrorCodeEnum.API_ERROR_212039.getMsg(), name, productName, batchSeqOperationEnum.getName(), batchSeqOperationEnum.getSaasName()));
                            }
                        }
                    }
                }
            }
        }

        param.clear();
        param.put("corpid", corpid);
        param.put("del", 0);
        param.put("idIn", parentIdList);
        List<ProductEntityExt> entitys = productModel.findEntitys(param);
        for (ProductEntityExt entity : entitys) {
            JSONObject data = entity.getData();
            Integer enableBatch = data.getInteger(ProductEnum.ENABLE_BATCH_SHELF_LIFE.getAttr());
            if (!Objects.equals(enableBatch, 1)) {
                disableBatchProducts.add(entity.getId());
            }
        }

        return disableBatchProducts;
    }

}
